﻿using System;
using System.Windows.Media;
using Avaxo.Scripting;

namespace Avaxo.Console
{
    public static class TextColors
    {
        private static readonly Color[] colors = new Color[Enum.GetNames( typeof ( TextType ) ).Length];

        public static Color GetColor( TextType type )
        {
            return EnsureColor( type );
        }

        private static Color EnsureColor( TextType type )
        {
            int index = (int) type;
            if ((index < 0) || (index >= colors.Length))
            {
                return default( Color );
            }
            lock (colors.SyncRoot)
            {
                if ( colors[index] == default( Color ) )
                {
                    Color color = CreateColor( type );
                    colors[ index ] = color;
                }
            }
            return colors[ (int) type ];
        }

        private static Color CreateColor( TextType type )
        {
            switch (type)
            {
                case TextType.Default:
                case TextType.Input:
                default:
                {
                    return Colors.Black;
                }
                case TextType.Prompt:
                {
                    return Colors.Gray;
                }
                case TextType.Output:
                {
                    return Color.FromRgb( 50, 0, 180 );
                }
                case TextType.Error:
                {
                    return Color.FromRgb( 150, 0, 0 );
                }
                case TextType.Header:
                {
                    return Colors.Gray;
                }
                case TextType.Comment:
                {
                    return Colors.Green;
                }
                case TextType.String:
                {
                    return Color.FromRgb( 180, 0, 0 );
                }
                case TextType.Keyword:
                {
                    return Color.FromRgb( 0, 0, 220 );
                }
            }
        }
    }
}
